﻿using System;
using System.Xml;
using Notoric.Model.Internal;
using Notoric.Model.Packaging;

namespace Notoric.Model.Elements.CWNotation
{
    /// <summary>
    /// Represents a rest (silence).
    /// </summary>
    public class Rest : DurationalSymbol
    {
        #region Constructors

        /// <summary>
        /// Creates a new <see cref="Rest"/> instance.
        /// </summary>
        /// <param name="packagePart">
        /// <para>
        /// Type: <see cref="XmlPackagePart"/>
        /// </para>
        /// <para>
        /// The package part that owns this element.
        /// </para>
        /// </param>
        /// <param name="owner">
        /// <para>
        /// Type: <see cref="Staff"/>
        /// </para>
        /// <para>
        /// The model element that directly owns this element.
        /// </para>
        /// </param>
        /// <param name="presentedElement">
        /// <para>
        /// Type: <see cref="RestElement"/>
        /// </para>
        /// <para>
        /// The rest symbol presented by this instance.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Any of the arguments is <see langword="null"/>.
        /// </exception>
        internal Rest(XmlPackagePart packagePart, Staff owner, RestElement presentedElement)
            : base(packagePart, owner, presentedElement)
        {
            StaffPosition = 5;
        }

        /// <summary>
        /// Creates a new <see cref="Rest"/> instance.
        /// </summary>
        /// <param name="packagePart">
        /// <para>
        /// Type: <see cref="XmlPackagePart"/>
        /// </para>
        /// <para>
        /// The package part that owns this element.
        /// </para>
        /// </param>
        /// <param name="owner">
        /// <para>
        /// Type: <see cref="Staff"/>
        /// </para>
        /// <para>
        /// The model element that directly owns this element.
        /// </para>
        /// </param>
        /// <param name="element">
        /// <para>
        /// Type: <see cref="XmlElement"/>
        /// </para>
        /// <para>
        /// The XML element that holds the data of this object.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Any of the arguments is <see langword="null"/>.
        /// </exception>
        internal Rest(XmlPackagePart packagePart, Staff owner, XmlElement element)
            : base(packagePart, owner, element)
        {
        }

        #endregion

        #region CoreSymbol Members

        /// <inheritdoc/>
        public override void ProcessEnvironmentChange(Environment environment)
        {
            
        }

        #endregion

        #region DurationalSymbol Members

        /// <inheritdoc/>
        protected override XmlElement CreateSymbolElementCore(XmlDocument document)
        {
            var element = document.CreateElement(
                PackageVocabulary.PackageNamespacePrefix,
                PackageVocabulary.RestElementName,
                PackageVocabulary.PackageNamespaceUri
                );

            return element;
        }

        /// <inheritdoc/>
        public override double GetCoreWidth()
        {
            return FindOwner<Staff>().SpaceSize * 1.5;
        }

        #endregion
    }
}
